//
//  ZYXBuyVC.m
//  RuiBeiKang
//
//  Created by iOS开发1 on 2019/1/9.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXBuyVC.h"

#import "ZYXDownSuccessVC.h"
@interface ZYXBuyVC ()
///标题
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
///图片
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
///商品名称
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
///价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
///微信按钮
@property (weak, nonatomic) IBOutlet UIButton *weixinBtn;
///支付宝按钮
@property (weak, nonatomic) IBOutlet UIButton *zhifubaoBtn;

///提交订单的金额
@property (weak, nonatomic) IBOutlet UILabel *allMoneyLabel;

@property (strong,nonatomic) NSString *order_number;

@property (strong,nonatomic) NSString *orde_price;
@end

@implementation ZYXBuyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self.typeStr isEqualToString:@"1"]) {
        self.title = @"购买课程";
        self.titleLabel.text = @"课程信息";
    }else{
        self.title = @"会员充值";
        self.titleLabel.text = @"会员信息";
    }
    self.weixinBtn.selected = YES;
    [self loadData];
}
-(void)loadData{
    if ([self.typeStr isEqualToString:@"1"]) {
        ///购买的是课程
        [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_BUYPermiss) parmas:@{@"zid":self.zid,@"user_id":UID} successBloock:^(NSDictionary *responseObject) {
            NSLog(@"responseObject =%@",responseObject);
            if ([responseObject[@"code"] isEqualToNumber:@200]) {
                self.titleLabel.text = @"课程信息";
                self.nameLabel.text = responseObject[@"data"][@"title"];
                self.priceLabel.text = [NSString stringWithFormat:@"￥%@",responseObject[@"data"][@"price"]];
                  self.allMoneyLabel.text = [NSString stringWithFormat:@"￥%@",responseObject[@"data"][@"price"]];
                ///图片地址
                [self.imgView sd_setImageWithURL:[NSURL URLWithString:kImgAllUrl(responseObject[@"data"][@"picUrl"])] placeholderImage:IMG(@"imgLoading")];
               self.order_number = responseObject[@"data"][@"order_number"];
               self.orde_price = responseObject[@"data"][@"price"];
               
            }else{
                [JKToast showWithText:responseObject[@"message"]];
            }
            
        } failureBlock:^(NSError *error) {
            
        }];
        
        
    }else{
        ///购买的vip
        [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_BUYVIP) parmas:@{@"user_id":UID} successBloock:^(NSDictionary *responseObject) {
            NSLog(@"responseObject =%@",responseObject);
            if ([responseObject[@"code"] isEqualToNumber:@200]) {
                
                self.titleLabel.text = @"会员信息";
                self.nameLabel.text = responseObject[@"data"][@"title"];
                self.priceLabel.text = [NSString stringWithFormat:@"￥%@",responseObject[@"data"][@"price"]];
                self.allMoneyLabel.text = [NSString stringWithFormat:@"￥%@",responseObject[@"data"][@"price"]];
                ///图片地址
                [self.imgView sd_setImageWithURL:[NSURL URLWithString:kImgAllUrl(responseObject[@"data"][@"picUrl"])] placeholderImage:IMG(@"imgLoading")];
                self.order_number = responseObject[@"data"][@"order_number"];
                self.orde_price = responseObject[@"data"][@"price"];
                
            }else{
                [JKToast showWithText:responseObject[@"message"]];
            }
            
        } failureBlock:^(NSError *error) {
            
        }];
    }
}
#pragma mark 点击事件
///提交订单
- (IBAction)clickSumOrder:(UIButton *)sender {
    
    if ([self.typeStr isEqualToString:@"1"]) { NSLog(@"%@",@{@"user_id":UID,@"goods_id":self.zid,@"price":self.orde_price,@"order_number":self.order_number});
        [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_APPLENeiGou) parmas:@{@"user_id":UID,@"goods_id":self.zid,@"price":self.orde_price,@"order_number":self.order_number} successBloock:^(NSDictionary *responseObject) {
            NSLog(@"%@",responseObject);
            ZYXDownSuccessVC *vc = [[ZYXDownSuccessVC alloc]init];
            vc.typeStr = @"class";
            [self.navigationController pushViewController:vc animated:YES];
        } failureBlock:^(NSError *error) {
            
        }];
    }else{
        
        NSLog(@"%@",@{@"user_id":UID,@"price":self.orde_price,@"order_number":self.order_number});
        [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_APPLEVIP) parmas:@{@"user_id":UID,@"price":self.orde_price,@"order_number":self.order_number} successBloock:^(NSDictionary *responseObject) {
            NSLog(@"%@",responseObject);
            ZYXDownSuccessVC *vc = [[ZYXDownSuccessVC alloc]init];
            vc.typeStr = @"vip";
            [self.navigationController pushViewController:vc animated:YES];
        } failureBlock:^(NSError *error) {
            
        }];
        
        
        
    }
    

    
    
}
- (IBAction)clickWeixinBtn:(UIButton *)sender {
    self.weixinBtn.selected = YES;
    self.zhifubaoBtn.selected = NO;
}
- (IBAction)clickZhifubaoBtn:(UIButton *)sender {
    self.weixinBtn.selected = NO;
    self.zhifubaoBtn.selected = YES;
}

@end
